<?php
ob_start('ob_output');
function ob_output($html) {
	// 一些用户喜欢使用windows笔记本编辑文件，因此在输出时需要检查是否包含BOM头
	if (ord(substr($html, 0, 1)) === 239 && ord(substr($html, 1, 2)) === 187 && ord(substr($html, 2, 1)) === 191) $html = substr($html, 3);
	// gzip输出
	if(
		!headers_sent() && // 如果页面头部信息还没有输出
		extension_loaded("zlib") && // 而且zlib扩展已经加载到PHP中
		array_key_exists('HTTP_ACCEPT_ENCODING', $_SERVER) &&
		stripos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false // 而且浏览器说它可以接受GZIP的页面 
	) {
		$html = gzencode($html, 3);
		header('Content-Encoding: gzip'); 
		header('Vary: Accept-Encoding');
	}
	header('Content-Length: '.strlen($html));
	return $html;
}
require('../xingcai_config.php');
$pgsid=array('30','50','80','100','120','200','300','');
include(__DIR__."/inc/comfunc.php");
ini_set("display_errors", "on");
error_reporting(E_ALL);
//此处设置彩种id
$typeid=80;
//每页默认显示
$pgs=isset($_GET['pgs']) == true ? (int) $_GET['pgs'] : 30;
if(!in_array($pgs,$pgsid)) die("pgs error");

//当前页面
$page=isset($_GET['page']) == true ? (int) $_GET['page'] : 1;
if(!$page) $page=1;
//传参
$toUrl="?page=";
$params=http_build_query($_REQUEST, '', '&');
if(!$mydb) $mydb = new MYSQL($dbconf);
$gRs = $mydb->row($conf['db']['prename']."type","shortName","id=".$typeid);
if($gRs){
	$shortName=$gRs[0][0];
}

$fromTime = isset($_GET['fromTime']) == true ? $_GET['fromTime'] : '';
$toTime = isset($_GET['toTime']) == true ? $_GET['toTime'] : '';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:esun=""><head>
<title><?=$_SETTINGS["webName"] ?> - 查看历史号码走势</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/line.css"  rel="stylesheet" type="text/css">

<script type="text/javascript" src="/js/nsc/jquery-1.7.min.js?v=1.17.1.23"></script>
<script language="javascript" type="text/javascript" src="js/line.js"></script>

<script type="text/javascript" src="js/layui.js"></script>
<script type="text/javascript">window.onerror=function(){return true;}</script>
<script language="javascript">
fw.onReady(function(){
	Chart.init();	
	DrawLine.bind("chartsTable","has_line");

		DrawLine.color('#499495');
	DrawLine.add((parseInt(0)*10+5+1),2,10,0);
		DrawLine.color('#E4A8A8');
	DrawLine.add((parseInt(1)*10+5+1),2,10,0);
		DrawLine.color('#499495');
	DrawLine.add((parseInt(2)*10+5+1),2,10,0);
		DrawLine.color('#E4A8A8');
	DrawLine.add((parseInt(3)*10+5+1),2,10,0);
		DrawLine.color('#499495');
	DrawLine.add((parseInt(4)*10+5+1),2,10,0);
		DrawLine.draw(Chart.ini.default_has_line);
	if($("#chartsTable").width()>$('body').width()){
	   $('body').width($("#chartsTable").width() + "px");
	}
	$("#container").height($("#chartsTable").height() + "px");
	$("#missedTable").width($("#chartsTable").width() + "px");
    resize();

	var nols = $(".ball04,.ball03");
	$("#no_miss").click(function(){
		var checked = $(this).attr("checked");
		$.each(nols,function(i,n){
			if(checked==true || checked=='checked'){
				n.style.display='none';
			}else{
				n.style.display='block';
			}
		});
	});
	//切换漏号分析
	$('.lhfx_tit').hover(function(){
		$('.lhfx_lotterylist').show();
		$('.lhfx_lotterylist').unbind().hover(function(){
		},function(){
			$(this).hide();
		});
	},function(){});
});
function resize(){
    window.onresize = func;
    function func(){
        window.location.href=window.location.href;
    }
}
$(function(){
	$(".datetxt").datepicker({ onSelect: function(dateText, inst) {$(this).val(dateText);} });	
})
</script>
<script>
layui.use('laydate', function(){
  var laydate = layui.laydate;
  
  var start = {
    min: laydate.now()
    ,max: '2099-06-16 23:59:59'
    ,istoday: false
    ,choose: function(datas){
      end.min = datas; //开始日选好后，重置结束日的最小日期
      end.start = datas //将结束日的初始值设定为开始日
    }
  };
  
  var end = {
    min: laydate.now()
    ,max: '2099-06-16 23:59:59'
    ,istoday: false
    ,choose: function(datas){
      start.max = datas; //结束日选好后，重置开始日的最大日期
    }
  };
  
  document.getElementById('LAY_demorange_s').onclick = function(){
    start.elem = this;
    laydate(start);
  }
  document.getElementById('LAY_demorange_e').onclick = function(){
    end.elem = this
    laydate(end);
  }
  
});
</script>

<body style="background:none;">
<div id="searchBox" style="background: #f8f8f8; padding:10px 0;">
	<div class="lhfx_tit"><span><?=$shortName?></span><span class="showAll"></span>基本走势</div>
    <div class="secondary_tabs">
        <ul>
            <li data="num_30" class="hover"><a href="?typeid=<?=$typeid?>&pgs=30" class="ml10<?php if($pgs==30) echo ' on'?>" target="_self">最近30期</a></li>
            <li data="num_50"><a href="?typeid=<?=$typeid?>&pgs=50" class="ml10<?php if($pgs==50) echo ' on'?>" target="_self">最近50期</a></li>
            <li data="num_100"><a href="?typeid=<?=$typeid?>&pgs=80" class="ml10<?php if($pgs==80) echo ' on'?>" target="_self">最近80期</a></li>
			<li data="num_100"><a href="?typeid=<?=$typeid?>&pgs=200" class="ml10<?php if($pgs==200) echo ' on'?>" target="_self">最近200期</a></li>
			<li data="num_100"><a href="?typeid=<?=$typeid?>&pgs=300" class="ml10<?php if($pgs==300) echo ' on'?>" target="_self">最近300期</a></li>
        </ul>
    </div>
    	<div class="lhfx_search_time">
		<form action="" method="get">
		<input type="hidden" name="typeid" value="<?=$typeid?>" />
            <input type="hidden" name="pgs" value="<?=$pgs?>" />
		时间范围：
		<input type="text" value="<?=$fromTime?>" name="fromTime" onclick="layui.laydate({elem: this, festival: true})" class="time_input">
		<span class="image"></span>
		<label>至</label>
		<input type="text" value="<?=$toTime?>" onclick="layui.laydate({elem: this, festival: true})" name="toTime" class="time_input">
		<span class="image"></span>
		<input type="submit" value="查询" id="showissue1" class="time_btn">
		</form>
	</div>
	<div class="clearfix"></div>
</div>
<div class="wo_choose">
<span>标注形式选择</span><input type="checkbox" name="checkbox2" value="checkbox" id="has_line" class="no_bk-bg"><label for="has_line">显示走势折线</label>
    <input type="checkbox" name="checkbox" value="checkbox" id="no_miss" onclick="toggleMiss();" /><label for="has_line">不带遗漏数据</label> 
	</div>


<div style="position: relative; height: 1107px;" id="container">
<table id="chartsTable" width="100%" cellpadding="0" cellspacing="0" border="0" style="position:absolute; top:0; left:0;">
    <tbody>
	  	<tr id="title">
            <td rowspan="2"><strong>期号</strong></td>
            <td rowspan="2" colspan="7" class="redtext"><strong>开奖号码</strong></td>
            <td colspan="33"><strong>红球</strong></td>
            <td colspan="16"><strong>蓝球</strong></td>
        </tr>
        <tr id="head">
            <?php for($i = 1; $i <= 33; $i++){ ?>
            <td class="wdh" align="center"><strong><?=$i < 10 ? "0" . $i : $i ?></strong></td>
            <?php } ?>
            <?php for($i = 1; $i <= 16; $i++){ ?>
            <td class="wdh" align="center"><strong><?=$i < 10 ? "0" . $i : $i ?></strong></td>
            <?php } ?>
        </tr>
          		<?php
				if($fromTime) $fromTime=strtotime($fromTime);
				if($toTime) $toTime=strtotime($toTime)+24*3600;
				
				$pg = $page;
				if(!$pg){$pg=1;}
				if(!$pgs){$pgs=30;}
				$five = array();
				$tableStr=$conf['db']['prename']."data";
				$tableStr2=$conf['db']['prename']."data a";
				$fieldsStr="time, number, data";
				
				$fieldsStr2="a.time, a.number, a.data";
				$whereStr=" type=$typeid ";
				$whereStr2=" a.type=$typeid ";
				if($fromTime && $toTime){
					$whereStr.=" and time between $fromTime and $toTime";
					$whereStr2.=" and a.time between $fromTime and $toTime";
				}elseif($fromTime){
					$whereStr.=' and time>='.$fromTime;
					$whereStr2.=' and a.time>='.$fromTime;
				}elseif($toTime){
					$whereStr.=' and time<'.$toTime;
					$whereStr2.=' and a.time<'.$toTime;
				}else{

				}
				$orderStr=" order by a.id desc";//排序
				//$data=array_reverse($data);//排序
				$totalNumber = $mydb->row_count($tableStr,$whereStr);

				if ($totalNumber>0){
			 
                $countcount=0;
				$perNumber=$pgs; //每页显示的记录数
				$page=$pg; //获得当前的页面值
				if (!isset($page)) $page=1;
				
				$totalPage=ceil($totalNumber/$perNumber); //计算出总页数
				$startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录
				$data = $mydb->row($tableStr2,$fieldsStr2,$whereStr2.' '.$orderStr." limit $startCount,$perNumber");
				
				if($data) foreach($data as $var){
					list($hongqiu, $lanqiu) = explode("|", $var[2]);
				
				echo '<tr>';
				echo '<td id="title">'.$var[1].'</td>';
				$dArry = explode(",", $hongqiu);
				for($i = 0; $i < 6; $i++){
					$var['h' . ($i + 1)] = (int) $dArry[$i];
					echo '<td class="wdh" align="center"><div class="ball02">' . $dArry[$i] . '</div></td>';
				}
				echo '<td class="wdh" align="center"><div class="ball01">' . $lanqiu . '</div></td>';

				for($i=0;$i<33;$i++){ //红球
					if($i == $var['h1'] || $i == $var['h2'] || $i == $var['h3'] || $i == $var['h4'] || $i == $var['h5'] || $i == $var['h6']){
						echo '<td class="charball" align="center"><div class="ball02">';
						
						switch ($i) {
							case $var['h1']:
								echo $var['h1'];
								break;
							case $var['h2']:
								echo $var['h2'];
								break;
							case $var['h3']:
								echo $var['h3'];
								break;
							case $var['h4']:
								echo $var['h4'];
								break;
							case $var['h5']:
								echo $var['h5'];
								break;
							case $var['h6']:
								echo $var['h6'];
								break;
							default:
								break;
						}

						echo '</div></td>';
						$five['LH'.$i] = 0;  //遗漏
						if(isset($five['SH'.$i]) == true && $five['SH'.$i]){
							$five['SH'.$i] ++;
						}else{
							$five['SH'.$i] = 1;
						} //出现总次数
						if(isset($five['LCH'.$i]) == true && $five['LCH'.$i]){
							$five['LCH'.$i]++;
						}else{
							$five['LCH'.$i]=1;
						} //最大连出值
					}else{
						if(isset($five['LH'.$i]) == true && $five['LH'.$i]){
							$five['LH'.$i]++;
						}else{
							$five['LH'.$i] = 1;
						}
						echo '<td class="wdh" align="center"><div class="ball03">'.$five['LH'.$i].'</div></td>';
						$five['LCH'.$i] = 0;
					}
					//遗漏总计
					if(isset($five['ZH'.$i]) == true){
						$five['ZH'.$i] += $five['LH'.$i];
					}else{
						$five['ZH'.$i] = $five['LH'.$i];
					}
					//最大遗漏值
					if(isset($five['MH'.$i]) == false || $five['MH'.$i] < $five['LH'.$i]){
						$five['MH'.$i] = $five['LH'.$i];
					}
					//最大连出值
					if(isset($five['MLCH'.$i]) == false || $five['MLCH'.$i] < $five['LCH'.$i]){
						$five['MLCH'.$i] = $five['LCH'.$i];
					}
				}

				for($i=0;$i<16;$i++){  //蓝球
					if($i==$lanqiu){
						echo '<td class="charball" align="center"><div class="ball01">'.$lanqiu.'</div></td>';
						$five['LL'.$i]=0;
						if(isset($five['SL'.$i]) == true && $five['SL'.$i]){
							$five['SL'.$i]++;
						}else{
							$five['SL'.$i] = 1;
						}
						if(isset($five['LCL'.$i]) == true && $five['LCL'.$i]){
							$five['LCL'.$i]++;
						}else{
							$five['LCL'.$i] = 1;
						}
					}else{
						if(isset($five['LL'.$i]) == true && $five['LL'.$i]){
							$five['LL'.$i]++;
						}else{
							$five['LL'.$i] = 1;
						}
						echo '<td class="wdh" align="center"><div class="ball03">'.$five['LL'.$i].'</div></td>';
						$five['LCL'.$i]=0;
					}
					if(isset($five['ZL'.$i]) == true && $five['ZL'.$i]){
						$five['ZL'.$i] += $five['LL'.$i];
					}else{
						$five['ZL'.$i] = $five['LL'.$i];
					}
					if(isset($five['ML'.$i]) == false || $five['ML'.$i] < $five['LL'.$i]){
						$five['ML'.$i] = $five['LL'.$i];
					}
					if(isset($five['MLCL'.$i]) == false || $five['MLCL'.$i] < $five['LCL'.$i]){
						$five['MLCL'.$i] = $five['LCL'.$i];
					}
				}
			
			echo '</tr>';
            }
		?>
    <tr>
    <td nowrap="">出现总次数</td>
    <td align="center" colspan="7">&nbsp;</td>
    <?php 
		for($i = 0; $i < 33; $i++){
			$five['DH' . $i] = isset($five['SH' . $i]) == true && $five['SH' . $i] ? $five['SH' . $i] : 0;
			echo '<td align="center">' . $five['DH' . $i] . '</td>';
		}
		for($i = 0; $i < 16; $i++){
			$five['DL' . $i] = isset($five['SL' . $i]) == true && $five['SL' . $i] ? $five['SL' . $i] : 0;
			echo '<td align="center">' . $five['DL' . $i] . '</td>';
		}
	?>
    </tr>
    <tr>
    <td nowrap="">平均遗漏值</td>
    <td align="center" colspan="7">&nbsp;</td>
    <?php 
		for($i = 0; $i < 33; $i++){
			$five['PH' . $i] = (int) ($pgs/($five['DH' . $i] + 1));
			echo '<td align="center">' . $five['PH' . $i] . '</td>';
		}
		for($i = 0; $i < 16; $i++){
			$five['PL' . $i] = (int) ($pgs/($five['DL' . $i] + 1));
			echo '<td align="center">' . $five['PL' . $i] . '</td>';
		}
	?>
    </tr>
    <tr>
    <td nowrap>最大遗漏值</td>
    <td align="center" colspan="7">&nbsp;</td>
    <?php 
		for($i = 0; $i < 33; $i++){
			$five['MaxH' . $i] = $five['MH' . $i] ? $five['MH' . $i] : 0;
			echo '<td align="center">' . $five['MaxH' . $i] . '</td>';
		}
		for($i = 0; $i < 16; $i++){
			$five['MaxL' . $i] = $five['ML' . $i] ? $five['ML' . $i] : 0;
			echo '<td align="center">' . $five['MaxL' . $i] . '</td>';
		}
	?>
    </tr>
    <tr>
    <td nowrap>最大连出值</td>
    <td align="center" colspan="7">&nbsp;</td>
    <?php 
		for($i = 0; $i < 33; $i++){
			$five['MaxLC' . $i] = isset($five['MLC' . $i]) == true && $five['MLC' . $i] ? $five['MLC' . $i] : 0;
			echo '<td align="center">' . $five['MaxLC' . $i] . '</td>';
		}
		for($i = 0; $i < 16; $i++){
			$five['MaxLC' . $i] = isset($five['MLC' . $i]) == true && $five['MLC' . $i] ? $five['MLC' . $i] : 0;
			echo '<td align="center">' . $five['MaxLC' . $i] . '</td>';
		}
	?>
    </tr>
    <tr id="head">
        <td rowspan="2"><strong>期号</strong></td>
        <td rowspan="2" colspan="7" class="redtext"><strong>开奖号码</strong></td>
        <?php for($i = 1; $i <= 33; $i++){ ?>
        <td class="wdh" align="center"><strong><?=$i < 10 ? "0" . $i : $i ?></strong></td>
        <?php } ?>
        <?php for($i = 1; $i <= 16; $i++){ ?>
        <td class="wdh" align="center"><strong><?=$i < 10 ? "0" . $i : $i ?></strong></td>
        <?php } ?>
    </tr>
    <tr id="title">
        <td colspan="33"><strong>红球</strong></td>
        <td colspan="16"><strong>蓝球</strong></td>
    </tr>
    <?php } ?>
</tbody></table>
</div>
<?php include "./inc/lotterylist.php"; ?>
</body>
</html>